package com.lcf.Flower;

import java.util.Scanner;

/**
 * @author 懒洋洋不懒
 * @version 1.0
 * @date 2025/4/11 16:45
 * @description
 */
public class FlowerMgr {



        private Flower[] flowers = new Flower[5];
        private Scanner scanner = new Scanner(System.in);

        public void inital() {
            flowers[0] = new Flower(1001, "金色海岸-香槟玫瑰", 10, 318.0, "2016-12-12", "王二妮", "");
            flowers[1] = new Flower(1002, "初心永不变-白玫瑰", 99, 538.0, "2016-12-20", "张欣雨", "");
            flowers[2] = new Flower(1003, "梦里花开-紫色桔梗", 40, 148.0, "2016-12-24", "王二妮", "眼波如水，映出窗外繁星点点");
            flowers[3] = new Flower(1004, "心花怒放-粉青百合", 120, 188.0, "2016-12-26", "王二妮", "内层银灰色厚棉纸，外层深蓝色条纹纸，银灰色缎带");
            flowers[4] = new Flower(1005, "致青春-无声的爱", 1000, 219.0, "2016-12-18", "张欣雨", "我爱你，胜过爱爱情，更胜过爱自己！");
        }

        public void mainMenu() {
            System.out.println("=====================================");
            System.out.println("欢迎光临\"七彩鲜花\"销售管理系统");
            System.out.println("=====================================");
            System.out.println("1. 查询销售订单");
            System.out.println("2. 修改销售订单");
            System.out.println("3. 删除销售订单");
            System.out.println("4. 系统退出");
            System.out.println("=====================================");

            while (true) {
                System.out.print("请选择操作：");
                int choice = scanner.nextInt();
                scanner.nextLine(); // Consume newline

                switch (choice) {
                    case 1:
                        searchAll();
                        break;
                    case 2:
                        updateSale();
                        break;
                    case 3:
                        deleteSale();
                        break;
                    case 4:
                        System.out.println("系统退出");
                        scanner.close();
                        return;
                    default:
                        System.out.println("无效选择，请重新输入！");
                }
            }
        }

        private void searchAll() {
            System.out.println("=====================================");
            System.out.println("查询销售订单");
            System.out.println("=====================================");
            for (Flower flower : flowers) {
                System.out.println(flower);
            }
        }

        private void updateSale() {
            System.out.println("=====================================");
            System.out.println("修改销售订单");
            System.out.println("=====================================");
            System.out.print("请输入销售编号：");
            int id = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            for (Flower flower : flowers) {
                if (flower.id == id) {
                    System.out.println("您要修改的订单详细信息如下：");
                    System.out.println(flower);
                    System.out.print("请输入修改后的鲜花名称：");
                    String name = scanner.nextLine();
                    System.out.print("请输入修改后的销售数量：");
                    int quantity = scanner.nextInt();
                    scanner.nextLine(); // Consume newline
                    System.out.print("请输入修改后的鲜花价格：");
                    double price = scanner.nextDouble();
                    scanner.nextLine(); // Consume newline
                    System.out.print("请输入修改后的销售日期(yyyy-MM-dd)：");
                    String saleDate = scanner.nextLine();
                    System.out.print("请输入修改后的销售员：");
                    String salesman = scanner.nextLine();
                    System.out.print("请输入修改后的备注：");
                    String remarks = scanner.nextLine();

                    flower.name = name;
                    flower.quantity = quantity;
                    flower.price = price;
                    flower.saleDate = saleDate;
                    flower.salesman = salesman;
                    flower.remarks = remarks;

                    System.out.println("修改成功！");
                    return;
                }
            }
            System.out.println("对不起，您要修改的订单号不存在！");
        }

        private void deleteSale() {
            System.out.println("=====================================");
            System.out.println("删除销售订单");
            System.out.println("=====================================");
            System.out.print("请输入要删除的订单编号：");
            int id = scanner.nextInt();
            scanner.nextLine(); // Consume newline

            boolean found = false;
            for (int i = 0; i < flowers.length; i++) {
                if (flowers[i].id == id) {
                    found = true;
                    System.out.println("您要修改的订单详细信息如下：");
                    System.out.println(flowers[i]);
                    System.out.print("确定要删除吗？(y/n)：");
                    String confirm = scanner.nextLine();
                    if ("y".equalsIgnoreCase(confirm)) {
                        for (int j = i; j < flowers.length - 1; j++) {
                            flowers[j] = flowers[j + 1];
                        }
                        flowers[flowers.length - 1] = null;
                        System.out.println("删除成功！");
                        return;
                    }
                }
            }
            if (!found) {
                System.out.println("对不起，没有您要删除的销售编号！");
            }
        }
    }

